<template>
	
	<view class="">
		<headerinfo></headerinfo>
		<view class="width60">
			<view class="Follow-auto friend_Page" @touchstart="refreshStart" @touchmove="refreshMove" @touchend="refreshEnd">
				<u-navbar title="聊天列表" :autoBack="true"></u-navbar>
						<refresh ref="refresh" @isRefresh="isRefresh"></refresh>
				<view class="list" v-for="(item,index) in list" :key="index" @click.stop="liaotian(item)">
					<image  :src="item.avatar" mode="aspectFill"></image>
					<view class="title">
						{{item.showName}}
					</view>
					<view class="desc">
						{{item.lastMessage}}
					</view>
					
					<view class="rightboix">
						<span class="btn" style="margin-top: 10rpx;" >
							聊天
						</span>
					</view>
					
				</view>
				
				<view class="nomore">
					没有更多了 ~
				</view>
				
				<nodata v-if="list.length == 0"></nodata>
			</view>
		</view>
	</view>
	

</template>

<script>
	import refresh from '@/components/refresh.vue';
	export default {
		components: {refresh},
		data() {
			return {
				list: [],
				type:1,
				query:{
					lastDocId:"",
					pageSize:10,
					queryFan:true,
				}
			};
		},
		onLoad(e) {
			this.type = e.queryFan
			this.query.lastDocId = ''
			this.getdata()
		},
		onReachBottom() {
			this.getdata(1)
		},
		methods: {
			// 刷新touch监听
			refreshStart(e) {
				this.$refs.refresh.refreshStart(e);
			},
			refreshMove(e) {
				this.$refs.refresh.refreshMove(e);
			},
			refreshEnd(e) {
				this.$refs.refresh.endAfter(e);
				this.query.lastDocId = ''
				this.getdata()
			},
			isRefresh() {
				this.$refs.refresh.refreshEnd(e);
				this.query.lastDocId = ''
				this.getdata()
			},
			toOther(username){
				uni.navigateTo({
					url:`/pagesfriend/tabbar/other?username=${username}`
				})
			},
			liaotian(item){
				let username = item.fanUsername
			  	uni.navigateTo({
			  		url:`/pagesfriend/chat/chat?username=${username}`
			  	})
			},
			getdata(type) {
				if(this.type == 1){
					this.query.queryFan = false
				}else{
					this.query.queryFan = true
				}
				this.$api2.getMyMessage(this.query).then(res => {
					
					console.log('我的消息')
					console.log(res)
					
					
					if(type == 1){
						this.list = [...this.list,...res.list]
					}else{
						if(res.list.length>0){
							let num = res.list.length-1
							this.query.lastDocId = res.list[num].docId
							
							if(type == 1){
								this.list = [...this.list,...res.list]
							}else{
								this.list = res.list
							}
						}else{
							this.list = []
						}
					}
					
					console.log(res)
				})
			},
			quxiao(item){
				console.log(item)
				uni.showModal({
					title: '提示',
					content: '是否确认取消关注？',
					success:  (res)=> {
						if (res.confirm) {
							let data = {
								focus:false,
								followeeId:item.username
							}
							this.$api2.followfocus(data).then(res=>{
								this.$Show.show('取消成功')
								this.getdata()
							})
						} 
					}
				});
			}
		
		}
	};
</script>


<style lang="scss" scoped>
	.Follow-auto{
		height: 100vh;
		overflow-y: scroll;
	}
	.list{
		height: 150rpx;
		display: flex;
		flex-direction: column;
		justify-content: center;
		position: relative;
		padding-left: 140rpx;
		border-bottom: 1px solid #f8f8f8;
		font-size: 32rpx;
		image{
			position: absolute;
			left: 20rpx;
			top: 50%;
			transform: translateY(-50%);
			width: 90rpx;
			height: 90rpx;
			border-radius: 50%;
		}
		.desc{
			font-size: 30rpx;
			color: #666;
			margin-top: 10rpx;
		}
		
		.rightboix{
			display: flex;
			flex-direction: column;
			position: absolute;
			right: 20rpx;
			top: 50%;
			transform: translateY(-50%);
		}
		
		.btn{
			display: inline-block;
			padding:10rpx 30rpx;
			background-color: #25d4d0;
			color: #fff;
			border-radius: 60px;
			text-align: center;
			font-size: 30rpx;
		}
	}
</style>